import { StaffVo } from '@/definition/vo/StaffVo';
import { StaffCreateDto, StaffQueryDto } from '@/definition/dto/StaffDto';
import { ProductMenuQueryDto } from '@dto/ProductDto';
import {get,put,post,deletes,upload} from './request';
import { ProductItemVo, ProductMenuVo } from "@vo/ProductVo";
import { ProductItemCreateDto, ProductMenuCreateDto,ProductItemQueryDto } from '@/definition/dto/ProductDto';
import { CartQueryDto, CartRefreshDto } from '@/definition/dto/CartDto';
import { CartProductsVo, CartVo } from '@/definition/vo/CartVo';
import { AuthLoginVo, StoreVo } from '@/definition/vo/AuthVo';
import { AuthLoginDto, AuthRegisterDto } from '@/definition/dto/AuthDto';
interface PaginationQuery<T>{
    total:number,
    items:T[]
}

interface ApiModelProps{

    /**
     * security
     */
    login:Function,
    code:Function,
    register:Function,
    forget:Function,
    queryStoreItems:Function,

      /**
     * 文件上传
     */
       uoloadFiles:Function,
    /**ProductItemVo
     * 商品列表
     * products/items
     */
    queryProductItems:Function,
    queryProdutItem:Function,
    createProductItem:Function,
    updateProductItem:Function,
    deleteProductItem:Function,
    /**ProductItemVo
     * 商品菜单
     * products/menus
     */
    queryProductMenuItems:Function,
    queryProductMenuItem:Function,
    createProductMenuItem:Function,
    updateProductMenuItem:Function,
    deleteMenuItem:Function,
    /**
     * 购物车
     * carts
     */

    queryCartItems:Function,
    queryCartItem:Function,
    createCartItem:Function,
    updateCartItem:Function,
    clearCartItem:Function,
    deleteCartItem:Function,

    /**
     * 员工 staffs
     */
    queryStaffItems:Function,
    createStaffItem:Function,
    updateStaffItem:Function,
    deleteStaffItem:Function,

    /**
     * alipay
     */
    payment:Function
    


}

const API:ApiModelProps = {
    /**
     * alipay
     */
    payment(){
        return post(`/alipay/code`)
    },

    /**
     * 
     * @returns 
     * queryStoreItems 查询店铺
     */
    login(data:AuthLoginDto):Promise<AuthLoginVo>{
        return post(`/auth/login`,data) 
    },
    code(email:string){
        return post(`/auth/code/${email}`)
    },
    register(data:AuthRegisterDto){
        return post(`/auth/register`,data) 
    },
    forget(){
        return post(`/auth/forget`) 
    },
    queryStoreItems():Promise<StoreVo>{
        return get(`/auth/store`) 
    },

    /**
     * 文件上传
     */
    uoloadFiles(date:any):Promise<any>{
        return upload(`/upload/files`,date);
    },
    /**ProductItemVo
     * 商品列表
     * products/items
     */
    queryProductItems(params:ProductItemQueryDto):Promise<PaginationQuery<ProductItemVo>>{
        return get(`/products/items`,params)
    },
    queryProdutItem(id:string):Promise<ProductItemVo>{
        return get(`/products/items/${id}`)
    },
    createProductItem(data:ProductItemCreateDto):Promise<void>{
        return post(`/products/items`,data);
    },
    updateProductItem(id:string,data:ProductItemCreateDto):Promise<void>{
        return put(`/products/items/${id}`,data)
    },
    deleteProductItem(id:string):Promise<void>{
        return deletes(`/products/items/${id}`)
    },
    /**ProductItemVo
     * 商品菜单
     * products/menus
     */
    queryProductMenuItems(params?:ProductMenuQueryDto):Promise<PaginationQuery<ProductMenuVo>>{
        return get(`/products/menus`,params);
    },
    queryProductMenuItem(id:string):Promise<ProductMenuVo>{
        return get(`/products/menus/${id}`);
    },
    createProductMenuItem(data:ProductMenuCreateDto):Promise<void>{
        return post(`/products/menus`,data);
    },
    updateProductMenuItem(id:string,data:ProductMenuCreateDto):Promise<void>{
        return put(`/products/menus/${id}`,data)
    },
    deleteMenuItem(id:string):Promise<void>{
        return deletes(`/products/menus/${id}`)
    },
    /**
     * 购物车
     * carts
     */

    queryCartItems(params?:CartQueryDto):Promise<PaginationQuery<CartVo>>{
        return get(`/carts`,params)
    },
    queryCartItem(cart:string):Promise<CartVo>{
        return get(`/carts/${cart}`)
    },
    createCartItem(data:CartProductsVo):Promise<CartVo>{
        return post(`/carts`,data)
    },
    updateCartItem(cart:string, data:CartProductsVo):Promise<CartVo>{
        return put(`/carts/${cart}`,data);
    },
    clearCartItem(cart:string):Promise<CartVo>{
        return put(`carts/${cart}/clear`);
    },
    deleteCartItem(cart:string):Promise<void>{
        return deletes(`/carts/${cart}`)
    },
     /**
     * 员工 staffs
     */
     queryStaffItems(params?:StaffQueryDto):Promise<PaginationQuery<StaffVo>>{
        return get(`/staffs`,params)
     },
     createStaffItem(data:StaffCreateDto){
        return post(`/staffs`,data)
     },
     updateStaffItem(id:string,data:StaffCreateDto):Promise<StaffVo>{
        return post(`/staffs/${id}`,data)
     },
     deleteStaffItem(id:string){
        return deletes(`/staffs/${id}`)
     },
     
}
export {API};
export type {PaginationQuery, ApiModelProps};